package org.dding.core.log;

import java.io.OutputStream;
import java.io.PrintStream;

public final class StreamLogger implements ILogger {

	private PrintStream print;

	/**
	 * Construct a new instance.
	 * 
	 * @param stream
	 *            the print stream to write to
	 */
	public StreamLogger(PrintStream stream) {
		if (stream == null) {
			throw new IllegalArgumentException("stream is null");
		}
		print = new PrintStream(stream);
	}

	/**
	 * Construct a new instance.
	 * 
	 * @param stream
	 *            the output stream to write to
	 */
	public StreamLogger(OutputStream stream) {
		this(new PrintStream(stream));
	}

	/** {@inheritDoc} */
	public void trace(final String message) {
		print.print("stream TRACE: ");
		print.println(message);
		print.flush();
	}

	/** {@inheritDoc} */
	public void trace(final String format, final Object arg1) {
		print.print("stream TRACE: ");
		print.printf(format, arg1);
		print.println();
		print.flush();
	}

	/** {@inheritDoc} */
	public void trace(final String format, final Object arg1, final Object arg2) {
		print.print("stream TRACE: ");
		print.printf(format, arg1, arg2);
		print.println();
		print.flush();
	}

	/** {@inheritDoc} */
	public void trace(final String format, final Object arg1,
			final Object arg2, final Object arg3) {
		print.print("stream TRACE: ");
		print.printf(format, arg1, arg2, arg3);
		print.println();
		print.flush();
	}

	/** {@inheritDoc} */
	public void trace(final String format, final Object... args) {
		print.print("stream TRACE: ");
		print.printf(format, (Object[]) args);
		print.println();
		print.flush();
	}

	/** {@inheritDoc} */
	public void trace(final Throwable t, final String message) {
		print.print("stream TRACE: ");
		print.print(message);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	/** {@inheritDoc} */
	public void trace(final Throwable t, final String format, final Object arg1) {
		print.print("stream TRACE: ");
		print.printf(format, arg1);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	/** {@inheritDoc} */
	public void trace(final Throwable t, final String format,
			final Object arg1, final Object arg2) {
		print.print("stream TRACE: ");
		print.printf(format, arg1, arg2);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	/** {@inheritDoc} */
	public void trace(final Throwable t, final String format,
			final Object arg1, final Object arg2, final Object arg3) {
		print.print("stream TRACE: ");
		print.printf(format, arg1, arg2, arg3);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	/** {@inheritDoc} */
	public void trace(final Throwable t, final String format,
			final Object... args) {
		print.print("stream TRACE: ");
		print.printf(format, args);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	public void debug(final String message) {
		print.print("stream DEBUG: ");
		print.println(message);
		print.flush();
	}

	public void debug(final String format, final Object arg1) {
		print.print("stream DEBUG: ");
		print.printf(format, arg1);
		print.println();
		print.flush();
	}

	public void debug(final String format, final Object arg1, final Object arg2) {
		print.print("stream DEBUG: ");
		print.printf(format, arg1, arg2);
		print.println();
		print.flush();
	}

	public void debug(final String format, final Object arg1,
			final Object arg2, final Object arg3) {
		print.print("stream DEBUG: ");
		print.printf(format, arg1, arg2, arg3);
		print.println();
		print.flush();
	}

	public void debug(final String format, final Object... args) {
		print.print("stream DEBUG: ");
		print.printf(format, (Object[]) args);
		print.println();
		print.flush();
	}

	public void debug(final Throwable t, final String message) {
		print.print("stream DEBUG: ");
		print.print(message);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	public void debug(final Throwable t, final String format, final Object arg1) {
		print.print("stream DEBUG: ");
		print.printf(format, arg1);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	public void debug(final Throwable t, final String format,
			final Object arg1, final Object arg2) {
		print.print("stream DEBUG: ");
		print.printf(format, arg1, arg2);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	public void debug(final Throwable t, final String format,
			final Object arg1, final Object arg2, final Object arg3) {
		print.print("stream DEBUG: ");
		print.printf(format, arg1, arg2, arg3);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	public void debug(final Throwable t, final String format,
			final Object... args) {
		print.print("stream DEBUG: ");
		print.printf(format, args);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	public void info(final String message) {
		print.print("stream INFO: ");
		print.println(message);
		print.flush();
	}

	public void info(final String format, final Object arg1) {
		print.print("stream INFO: ");
		print.printf(format, arg1);
		print.println();
		print.flush();
	}

	public void info(final String format, final Object arg1, final Object arg2) {
		print.print("stream INFO: ");
		print.printf(format, arg1, arg2);
		print.println();
		print.flush();
	}

	public void info(final String format, final Object arg1, final Object arg2,
			final Object arg3) {
		print.print("stream INFO: ");
		print.printf(format, arg1, arg2, arg3);
		print.println();
		print.flush();
	}

	public void info(final String format, final Object... args) {
		print.print("stream INFO: ");
		print.printf(format, (Object[]) args);
		print.println();
		print.flush();
	}

	public void info(final Throwable t, final String message) {
		print.print("stream INFO: ");
		print.print(message);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	public void info(final Throwable t, final String format, final Object arg1) {
		print.print("stream INFO: ");
		print.printf(format, arg1);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	public void info(final Throwable t, final String format, final Object arg1,
			final Object arg2) {
		print.print("stream INFO: ");
		print.printf(format, arg1, arg2);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	public void info(final Throwable t, final String format, final Object arg1,
			final Object arg2, final Object arg3) {
		print.print("stream INFO: ");
		print.printf(format, arg1, arg2, arg3);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	public void info(final Throwable t, final String format,
			final Object... args) {
		print.print("stream INFO: ");
		print.printf(format, args);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	public void warn(final String message) {
		print.print("stream WARN: ");
		print.println(message);
		print.flush();
	}

	public void warn(final String format, final Object arg1) {
		print.print("stream WARN: ");
		print.printf(format, arg1);
		print.println();
		print.flush();
	}

	public void warn(final String format, final Object arg1, final Object arg2) {
		print.print("stream WARN: ");
		print.printf(format, arg1, arg2);
		print.println();
		print.flush();
	}

	public void warn(final String format, final Object arg1, final Object arg2,
			final Object arg3) {
		print.print("stream WARN: ");
		print.printf(format, arg1, arg2, arg3);
		print.println();
		print.flush();
	}

	public void warn(final String format, final Object... args) {
		print.print("stream WARN: ");
		print.printf(format, (Object[]) args);
		print.println();
		print.flush();
	}

	public void warn(final Throwable t, final String message) {
		print.print("stream WARN: ");
		print.print(message);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	public void warn(final Throwable t, final String format, final Object arg1) {
		print.print("stream WARN: ");
		print.printf(format, arg1);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	public void warn(final Throwable t, final String format, final Object arg1,
			final Object arg2) {
		print.print("stream WARN: ");
		print.printf(format, arg1, arg2);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	public void warn(final Throwable t, final String format, final Object arg1,
			final Object arg2, final Object arg3) {
		print.print("stream WARN: ");
		print.printf(format, arg1, arg2, arg3);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	public void warn(final Throwable t, final String format,
			final Object... args) {
		print.print("stream WARN: ");
		print.printf(format, args);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	public void error(final String message) {
		print.print("stream ERROR: ");
		print.println(message);
		print.flush();
	}

	public void error(final String format, final Object arg1) {
		print.print("stream ERROR: ");
		print.printf(format, arg1);
		print.println();
		print.flush();
	}

	public void error(final String format, final Object arg1, final Object arg2) {
		print.print("stream ERROR: ");
		print.printf(format, arg1, arg2);
		print.println();
		print.flush();
	}

	public void error(final String format, final Object arg1,
			final Object arg2, final Object arg3) {
		print.print("stream ERROR: ");
		print.printf(format, arg1, arg2, arg3);
		print.println();
		print.flush();
	}

	public void error(final String format, final Object... args) {
		print.print("stream ERROR: ");
		print.printf(format, (Object[]) args);
		print.println();
		print.flush();
	}

	public void error(final Throwable t, final String message) {
		print.print("stream ERROR: ");
		print.print(message);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	public void error(final Throwable t, final String format, final Object arg1) {
		print.print("stream ERROR: ");
		print.printf(format, arg1);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	public void error(final Throwable t, final String format,
			final Object arg1, final Object arg2) {
		print.print("stream ERROR: ");
		print.printf(format, arg1, arg2);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	public void error(final Throwable t, final String format,
			final Object arg1, final Object arg2, final Object arg3) {
		print.print("stream ERROR: ");
		print.printf(format, arg1, arg2, arg3);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	public void error(final Throwable t, final String format,
			final Object... args) {
		print.print("stream ERROR: ");
		print.printf(format, args);
		print.print(": ");
		t.printStackTrace(print);
		print.flush();
	}

	@Override
	public void trace(Throwable t) {
		print.print("stream TRACE: ");
		t.printStackTrace(print);
		print.flush();
	}

	@Override
	public void info(Throwable t) {
		print.print("stream INFO: ");
		t.printStackTrace(print);
		print.flush();

	}

	@Override
	public void error(Throwable t) {
		print.print("stream ERROR: ");
		t.printStackTrace(print);
		print.flush();
	}

	@Override
	public void warn(Throwable t) {
		print.print("stream WARN: ");
		t.printStackTrace(print);
		print.flush();

	}

	@Override
	public void debug(Throwable t) {
		print.print("stream DEBUG: ");
		t.printStackTrace(print);
		print.flush();

	}
}
